﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Portal.Common.Entity;
using Portal.Logic;

namespace Portal
{
    public partial class Left : System.Web.UI.Page
    {
        List<DectionaryEntity> parentLists;//父节点
        List<DectionaryEntity> subItems;//子节点
        List<DectionaryEntity> subChild;//子节点的下级节点
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                GetParentLists();
                BindTreeView();
            }
        }

        public void GetParentLists()
        {
            IList lists = Session["UserDeictionaryList"] as IList;
            if (lists != null)
            {
                if (lists.Count > 0)
                {
                    List<DectionaryEntity> objSet = (List<DectionaryEntity>)lists;
                    parentLists = objSet.FindAll(delegate(DectionaryEntity ety)
                    {
                        if (ety.PARENT_DICTIONARY_ID == "" || ety.PARENT_DICTIONARY_ID == null && ety.DICTIONARY_TYPE.ToLower() == "menu" && ety.DICTIONARY_ID!= "1")
                        {
                            return true;
                        }
                        return false;
                    });

                }
            }
        }

        public void BindTreeView()
        {
            subItems = new List<DectionaryEntity>();
            TreeNode node = new TreeNode();
            if (parentLists != null)
            {
                foreach (DectionaryEntity entity in parentLists)
                {
                    node = new TreeNode();
                    node.Text = entity.CN_NAME;
                    node.NavigateUrl = entity.EXT01;
                    
                    subItems = new DectionaryLogic().GetSubList(entity.DICTIONARY_ID);
                    foreach (DectionaryEntity subEntity in subItems)
                    {
                        TreeNode subNode = new TreeNode();
                        subNode.Text = subEntity.CN_NAME;
                        subNode.NavigateUrl = "javascript:GetSelectedNodeValue('"+subEntity.EXT01+"');";
                        subNode.ImageUrl = "images/fav1.jpg";
                        node.ChildNodes.Add(subNode);
                        subChild = new DectionaryLogic().GetSubList(subEntity.DICTIONARY_ID);
                       
                    }
                    tvMenuInfo.Nodes.Add(node);
                }

            }
        }
    }
}